<?php

/*----------------------------------------------+
|  MaxForum					|
|  ===========================================	|
|  By Majd Almontaser				|
|  Released under the License GNU v3.0		|
|  http://www.Max4Dev.com			|
|  ===========================================	|
|  Ttmtt Team - http://www.liioiil.com		|
+-----------------------------------------------*/

if (!defined('MAX_ON')){
	echo "<h1>ACCESS DENIED</h1>You cannot access this file directly.";
	exit();
}

#----------------------
# Setup
#----------------------
	
	# Load star rater
	require 'rater/_drawrating.php';
	
	# Starting hooks
	$Gallery->template('pages/gallery/view-cat.template.php')->hook('start', 2);

#-------------------------------------------------------------
# Get most rated images
#-------------------------------------------------------------

	$query = mysql_query('
		SELECT
			gi.id, gi.image, gi.title, gi.user, m.id as m_id, m.name as m_name
		
		FROM
			' . $db_prefix . 'gallery_images gi, ' . $db_prefix . 'gallery_images_ratings r, ' . $db_prefix . 'members m
			
		WHERE
			gi.user = m.id AND
			gi.id = r.image
		
		ORDER BY
			(r.total_value / r.total_votes) DESC
			
		LIMIT
			' . $Gallery->setting('image_perpage')
	);
	
	$totalRows	= @mysql_num_rows($query);
	$count		= 0;
	$rowNum		= 1;
	
	while ($row = @mysql_fetch_assoc($query))
	{
		$row['title'] = strip_slashes($row['title']);
		
		#------------------------------------
		# Format lang string
		#------------------------------------
		
			$var1 = '<a href="' . max_link('index.php?page=gallery&act=view-image&id=' . $row['id'], 'gallery/view-image/' . $row['id']) . '">' . $row['title'] . '</a>';
			
			$var2 = member_link($row['m_id'], 0);
			
			$image_title = sprintf($lang['image_title'], $var1, $var2);
			
		# Where is the image?
		$image		= '/uploads/gallery/images/t_' . $row['image'];
		$r_image	= '/uploads/gallery/images/r_' . $row['image'];
		
		$Gallery->hook(3);
		++$count;
		$rowNum = ($rowNum == 3) ? 0 : $rowNum + 1;
	}
	
$Gallery->hook(4, 'end');
?>
